package com.vegetable.modules.service.wx;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 企业微信部门同步定时任务
 * 定期同步企业微信通讯录部门结构
 *
 * @author Qoder
 */
@Slf4j
@Component
public class WxCpDepartmentSyncScheduledTask {

    @Autowired
    private WxCpDepartmentSyncService wxCpDepartmentSyncService;

    /**
     * 每天凌晨2点执行部门结构同步
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void syncDepartmentStructure() {
        try {
            log.info("开始执行企业微信部门结构同步定时任务");
            
            wxCpDepartmentSyncService.syncDepartmentStructure();
            
            log.info("企业微信部门结构同步定时任务执行完成");
        } catch (Exception e) {
            log.error("执行企业微信部门结构同步定时任务失败", e);
        }
    }
}